<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml"
      xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>每周三商机跟踪列表</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
          name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--插件样式-->
    <link rel="stylesheet" href="/dist/plugins/select2/select2.min.css">
    <!--插件样式-->
    <link href="/dist/plugins/ztree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet"/>
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=39cd89cd">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=16f1e6f3">
    <style>
        .table > tbody > tr > td {
            line-height: 24px;
            max-height: 24px;
            overflow: hidden;
        }

        span.lineOne {
            line-height: 28px;
            height: 28px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            /*-webkit-line-clamp: 1;*/
        }

        .div-td-content-more {
            position: absolute;
            height: auto;
            z-index: 999;
            line-height: 20px;
            background-color: #d3e8fd;
            padding: 8px 6px;
            border: 1px solid #e8e8ea;
            display: none;
        }

        .divCheck {
            height: 100%;
            margin-left: 5px;
            line-height: 25px;
        }

        .divCheck input {
            float: left;
            margin-top: 7px;
            margin-right: 5px;
        }

        .div-td-content-more i {
            width: 15px;
            height: 12px;
            background: url("/dist/img/more-icon.png");
            position: absolute;
            left: 50px;
            top: -12px;
        }

        .left {
            width: 170px;
            float: left;
        }

        .right {
            margin-left: 180px;
        }

        .templateStyle {
            border: 1px solid #ddd;
            padding: 0 10px;
        }
    </style>
</head>
<body>
<section class="content" id="app">
    <div class="div-td-content-more"><i></i></div>
    <iframe id="ifExprot" style="width:0px;height:0px;display: none;" frameborder="0"></iframe>
    <div class="row">
        <div v-if="currentUser.roleName!='区域经理'" class="left" id="inboxGroup" id="divLeft">
            <div class="box-body no-padding box-border iframeH"
                 style="overflow-y: auto;background: #f7f8fa;">
                <ul class="ztree" id="ztree"></ul>
            </div>
        </div>
        <div :class="currentUser.roleName!='区域经理'?'right':''">
            <div class="templateStyle iframeH" style="overflow-y: auto;">
                <div style="height: 25px;margin: 10px 0px;">
                    <input type="text" placeholder="关键字" class="form-control pull-left input-sm"
                           style="width: 200px;" v-model="searchParams.key">
                    <button type="button" class="btn oaBtn btn-sm"
                            style="margin-left: 10px;float: left;" @click="search">查询
                    </button>
                    <input type="button" class="btn oaBtn btn-sm pull-left" style="margin-left: 20px;" value="导出"
                           @click="exportGet"/>
                    <button v-if="currentUser.roleName=='区域经理'" type="button" class="btn oaBtn pull-right btn-sm" @click="trackBtn">
                        新增商机
                    </button>
                </div>
                <div class="box-body no-padding iframeH" style="overflow: auto;" id="scrollDiv">
                    <table class="table table-hover table-bordered text-center table-striped">
                        <thead>
                        <tr>
                            <th style="width: 60px">区域经理</th>
                            <th style="width: 61px">客户姓名</th>
                            <th style="width: 70px">客户电话</th>
                            <th style="width: 72px">客户所在地</th>
                            <th style="width: 66px">商机状态</th>
                            <th style="width: 80px">商机确认日期</th>
                            <th style="width: 60px">购机方式</th>
                            <th style="width: 55px">需求机型</th>
                            <th style="width: 61px">需求台量</th>
                            <th style="width: 70px">经销商报价</th>
                            <th>工况</th>
                            <th style="width: 90px">当前状态</th>
                            <th style="width: 42px;">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr v-for="(item,i) in list">
                            <td>{{item.regionalManagerName}}</td>
                            <td>
                                <span style="color:#2a8cec;cursor: pointer;" @click="goDetail('look',i)">{{item.customerName}}</span>
                            </td>
                            <td>{{item.customerTel}}</td>
                            <td><span class="lineOne">{{item.provinceName}}-{{item.cityName}}-{{item.countyName}}</span></td>
                            <td><span class="lineOne">{{item.confirmationStatus}}</span></td>
                            <td><span class="lineOne">{{item.confirmationDate}}</span></td>
                            <td><span class="lineOne">{{item.buyType}}</span></td>
                            <td><span class="lineOne">{{item.needModel}}</span></td>
                            <td>{{item.needNumber}}台</td>
                            <td><span class="lineOne">{{item.dealerquote}}万元</span></td>
                            <td><span class="lineOne">{{item.buildCondition}}</span></td>
                            <td>
                                <span v-if="(item.auditFlag==0&&currentUser.id==item.currentAuditorId) || item.auditFlag==2 " style="color:red;">{{convertAuditFlagToName(item)}}</span>
                                <span v-else>{{convertAuditFlagToName(item)}}</span>
                            </td>
                            <td v-if="currentUser.id==item.regionalManagerId && item.auditFlag=='-1'">
                                <a href="javascript:void(0);" @click="goDetail('edit',i)">&nbsp;编辑&nbsp;</a>
                            </td>
                            <td v-else-if="currentUser.id==item.regionalManagerId && item.auditFlag=='2' ">
                                <a href="javascript:void(0);" @click="goDetail('edit',i)">&nbsp;重新编辑&nbsp;</a>
                            </td>
                            <td v-else-if="currentUser.id==item.currentAuditorId && item.auditFlag=='0'">
                                <a href="javascript:void(0);" @click="goDetail('audit',i)">&nbsp;审核&nbsp;</a>
                            </td>
                            <td v-else>
                                <a href="javascript:void(0);" @click="goDetail('look',i)">&nbsp;查看&nbsp;</a>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <div class="oa-pager text-center" style="margin-top: 5px;">
                        共
                        <span id="allCount"> 0 </span>条记录&nbsp;&nbsp;&nbsp;
                        <span id="nowPage"> 1 </span>/<span id="allPage">1</span>&nbsp;&nbsp;&nbsp;
                        <span class="oa-pager-button" id="first">首页</span>
                        <span class="oa-pager-button" id="prev">上一页</span>
                        <span class="oa-pager-button" id="next">下一页</span>
                        <span class="oa-pager-button" id="last">尾页</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=7e54a132"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=558d0414"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript" src="/dist/plugins/My97DatePicker/WdatePicker.js"></script>
<!--ztree组件所需js-->
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.exhide-3.5.js"></script>
<script>
    $(function () {
        $("body").on("click", ".lineOne", function (e) {
            if ($(".div-td-content-more").is(":hidden")) {
                var text = $(this).text();
                if (text != "") {
                    text = "<i></i>" + text;
                    $(".div-td-content-more").html(text).css({
                        "width": $(this).outerWidth() + "px",
                        "left": $(this).offset().left,
                        "top": ($(this).offset().top + $(this).outerHeight()) + "px"
                    }).show();
                    e.stopPropagation();
                }
            } else {
                $(".div-td-content-more").hide();
            }
        });
        $("body").on("click", ".div-td-content-more", function (e) {
            e.stopPropagation();
        });
        $("body").on("click", function () {
            $(".div-td-content-more").hide();
        });
    });
</script>
<script type="text/javascript">
    var zTreeCallback = {
        showIcon: function (treeeId, treeNode) {
            return treeNode.isParent;
        },
        onClick: function (event, treeId, treeNode) {
            console.log(treeNode.type)
            if (treeNode.type == "company" && !app.isDaQuJingLi) {
                app.searchParams.companyId = treeNode.id;
                app.searchParams.bigRegionalId = '';
                app.searchParams.regionalManagerId = '';
                app.getThurTrackList();
            }
            if (treeNode.type == "depart") {
                app.searchParams.companyId = '';
                app.searchParams.bigRegionalId = treeNode.id;
                app.searchParams.regionalManagerId = '';
                app.getThurTrackList();
            }
            if (treeNode.type == "user") {
                app.searchParams.companyId = '';
                app.searchParams.bigRegionalId = '';
                app.searchParams.regionalManagerId = treeNode.id;
                app.getThurTrackList();
            }

        },
        beforeClick: function (treeId, treeNode, clickFlag) {
            // if (treeNode.level == 0) {
            //     return false;
            // }
        }
    };
    var zTreeSetting = {
        view: {
            showIcon: zTreeCallback.showIcon
        },
        data: {
            simpleData: {
                enable: true
            },
            keep: {
                parent: true
            }
        },
        callback: {
            onClick: zTreeCallback.onClick,
            beforeClick: zTreeCallback.beforeClick
        }
    };

</script>
<script type="text/javascript">

    var app = new Vue({
        el: '#app',
        data: {
            currentUser: getCurrentUser(),
            list: [],
            searchParams: {
                userId: $.wyui.page.urlParams.userId ? $.wyui.page.urlParams.userId : getCurrentUser().id,
                key: '',
                customerName: '',
                companyId: '',
                bigRegionalId: '',
                regionalManagerId: '',
                date: new Date().Format("yyyy-MM-dd"),
            },
            isDaQuJingLi: false
        },
        methods: {
            isShowBtn: function (eName) {
                if (getCurrentUser().superUser || ($.inArray(eName, this.rightOp) > -1)) {
                    return true;
                } else {
                    return false;
                }
            },
            fmoney: function (s, n) {
                n = n > 0 && n <= 20 ? n : 2;
                s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
                var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1],
                    t = "";
                for (i = 0; i < l.length; i++) {
                    t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
                }
                return t.split("").reverse().join("") + "." + r;
            },
            //新建
            trackBtn: function () {
//                $.dialog({
//                    content: 'url:/page/reportForm/salesForecastReport/ThursdayTrack.html?pageType=edit' + "&t="+ new Date(),
//                    title: '每周三商机跟踪',
//                    width: 904,
//                    height: 535,
//                    max: true,
//                    min: true,
//                    lock: true
//                });
                top.addTabs({
                    id: 'ThursdayTrack',
                    title: '每周三商机跟踪详情页',
                    close: true,
                    url: 'reportForm/salesForecastReport/thursdayTrack.html?pageType=edit' + "&day=" + new Date()
                });
            },
            //跳转页  编辑和查看
            goDetail: function (type, i) {
                top.closeTabByPageId("ThursdayTrack");
                var that = this;
                var id = that.list[i].id;
                console.log(id)
                var condition = '?id=' + id;
                if (type != 'edit') {
                    condition += '&pageType=' + type;
                    top.addTabs({
                        id: 'ThursdayTrack',
                        title: '每周三商机跟踪详情页',
                        close: true,
                        url: 'reportForm/salesForecastReport/thursdayTrack.html' + condition
                    });
                }
                if (type == 'edit') {
                    condition += '&pageType=edit';
                    top.addTabs({
                        id: 'ThursdayTrack',
                        title: '每周三商机跟踪详情页',
                        close: true,
                        url: 'reportForm/salesForecastReport/thursdayTrack.html' + condition + "&t=" + new Date()
                    });
                }
            },
            //列表页
            getThurTrackList: function () {
                var that = this;
                console.log("2")
                $.wyui.page.dataUrl = server.ip + urlConfig.thursday.getThurTrackList;
                var obj = {key: that.searchParams.key,
                    userId: that.currentUser.id,
                    companyId: that.searchParams.companyId,
                    bigRegionalId: that.searchParams.bigRegionalId,
                    regionalManagerId: that.searchParams.regionalManagerId,
                    dateTime: that.searchParams.date}
                $.extend($.wyui.page.queryParams, obj);
                $.wyui.page.getByPage_callback = function (r) {
                    that.list = r;
                    document.getElementById("scrollDiv").scrollTop = 0;
                };
                $.wyui.page.getByPage_scroll_callback = function (list) {
                    if (list.length < 30) {
                        isLoad = false;
                    } else {
                        for (var i = 0; i < list.length; i++) {
                            that.list.push(list[i]);
                        }
                        isLoad = true;
                    }
                };
                $.wyui.page.getByPage();
            },
            convertAuditFlagToName: function (item) {
                switch (Number(item.auditFlag)) {
                    case -1:
                        return "未提交";
                        break;
                    case 0:
                        return "待-"+item.currentAuditorName+"-审核";
                        break;
                    case 1:
                        return "已通过";
                        break;
                    case 2:
                        return "已驳回";
                        break;
                    default :
                        break;
                }
            },
            //查询方法
            search: function () {
                $.wyui.page.queryParams.requestPage = 1;
                $.extend($.wyui.page.queryParams, this.searchParams);
                this.getThurTrackList()
            },
            goClick: function (type) {
                var that = this;
                if (type == 'tiJiao') {
                    that.save(0);
                } else if (type == 'tongGuo') {
                    if (!confirm("确定要通过吗？")) {
                        return;
                    }
                    advise = '同意！';
                    $.wyui.postMethod(urlConfig.yuce.applyAudit, {
                            id: that.main.id,
                            auditFlag: 1,
                            advise: '同意!',
                            userId: that.list.userId
                        },
                        function (r) {
                            top.refreshTabByName("每周三商机跟踪详情页", "no");
                            top.closeTabByPageId("xsyc");
                        })
                    ;
                } else {
                    that.copierReturn();
                    return;
                }
            },
            //获取公司树
            getCompanyTree: function () {
                var that = this;
                $.wyui.postMethod(urlConfig.system.system.getCompanyTree, {
                    companyId: getCurrentUser().companyId
                }, function (nodes) {
                    console.log(nodes)
                    for (var i = 0; i < nodes.length; i++) {
                        if (nodes[i].name == '重庆迎风') {
                            nodes.splice(i, 1);
                        }
                    }
                    that.treeObj = $.fn.zTree.init($("#ztree"), zTreeSetting, nodes);
                    var treeObj = $.fn.zTree.getZTreeObj("ztree");
                    var nodes = treeObj.getNodes();
                    if (nodes[0].children[0]) {
                        //默认查集团
                        that.treeObj.selectNode(nodes[0]);
                        that.searchParams.companyId = nodes[0].children[0].id;
                        app.searchParams.bigRegionalId = '';
                        app.searchParams.regionalManagerId = '';
                        that.getThurTrackList();
                    }
                });
            },
            //获取树
            getTreeData: function () {
                var that = this;
                $.wyui.postMethod(urlConfig.thursday.getOrgTreeNodesByUserId, {
                    userId: getCurrentUser().id,
                }, function (nodes) {

                    var xiaoShouBuId = ''
                    var xiaoShouBuPid = ''

                    var fuWuBuId = ''
                    var fuWuBuIdPid = ''

                    var caiWuBuId = ''
                    var caiWuBuIdPid = ''
                    var i = nodes.length;
                    while (i--) {
                        if (nodes[i].name == '重庆迎风') {
                            nodes.splice(i, 1);
                        }
                        //只留销售部下的大区和人,并且移除销售部/服务部/财务部/节点
                        if (nodes[i].name == '销售部') {
                            xiaoShouBuId = nodes[i].id
                            xiaoShouBuPid = nodes[i].pId
                            nodes.splice(i, 1);
                        } else if (nodes[i].name == '服务部') {
                            fuWuBuId = nodes[i].id
                            fuWuBuIdPid = nodes[i].pId
                            nodes.splice(i, 1);
                        } else if (nodes[i].name == '财务部') {
                            caiWuBuId = nodes[i].id
                            caiWuBuIdPid = nodes[i].pId
                            nodes.splice(i, 1);
                        }
                        //不显示自己
                        if (nodes[i].id == currentUser.id && currentUser.roleName != '区域经理') {
                            nodes.splice(i, 1);
                        }
                    }

                    var i = nodes.length;
                    while (i--) {
                        //去除服务部和财务部的人
                        if (nodes[i].pId == fuWuBuId || nodes[i].pId == caiWuBuId) {
                            nodes.splice(i, 1);
                        }
                        //去除销售部管理的人
                        if (nodes[i].pId == xiaoShouBuId && nodes[i].type == 'user') {
                            nodes.splice(i, 1);
                        }
                    }

                    //重新拼接树
                    var i = nodes.length;
                    while (i--) {
                        if (nodes[i].pId == xiaoShouBuId) {
                            nodes[i].pId = xiaoShouBuPid
                        }
                    }
                    //console.log("过滤后tree = " + JSON.stringify(nodes))

                    that.treeObj = $.fn.zTree.init($("#ztree"), zTreeSetting, nodes);
                    var nodes = that.treeObj.getNodes();
                    if (getCurrentUser().roleName == '区域经理') {
                        //不显示树
                        //that.treeObj.expandAll(true);
                        //that.getSelectLastNode(nodes[0])
                        that.searchParams.companyId = '';
                        that.searchParams.bigRegionalId = '';
                        that.searchParams.regionalManagerId = currentUser.id;
                        that.getThurTrackList();
                    }
                    else if (getCurrentUser().roleName == '大区经理') {
                        that.isDaQuJingLi = true
                        //显示树且展开公司
                        that.treeObj.expandAll(true);
                        that.treeObj.selectNode(nodes[0].children[0].children[0])
                        that.searchParams.companyId = '';
                        that.searchParams.regionalManagerId = ''
                        that.searchParams.bigRegionalId = getCurrentUser().departId;
                        console.log("1")
                        that.getThurTrackList();
                    } else {
                        //默认查公司
                        that.searchParams.companyId = nodes[0].children[0].id;
                        that.treeObj.selectNode(nodes[0].children[0])
                        that.getThurTrackList();
                    }
                });
            },
            getSelectLastNode: function (currentNode) {
                var that = this;
                if (currentNode.children && currentNode.children.length > 0) {
                    var node = currentNode.children[0];
                    this.getSelectLastNode(node)
                } else {
                    //that.treeObj.selectNode(currentNode)
                }
            },
            /*exportGet: function () {
                $('#ifExprot').attr('src', server.ip
                    + "/thurTrack/getDownByCondition.json"
                    + '?userId=' + getCurrentUser().id
                    + '&companyId=' + getCurrentUser().companyId
                    + '&bigRegionalId=' + getCurrentUser().departId
                );
                return false;
            }*/
            exportGet: function () {
                var that = this;
                $.dialog({
                    content: 'url:/page/reportForm/salesForecastReport/chooseExportGetField.html?userId=' +that.searchParams.userId + "&key=" + that.searchParams.key + "&companyId=" + that.searchParams.companyId+ "&bigRegionalId=" + that.searchParams.bigRegionalId+ "&regionalManagerId=" + that.searchParams.regionalManagerId,
                    title: '选择导出字段',
                    width: 800,
                    height: 500,
                    max: true,
                    min: true,
                    lock: true
                });
            },
        },
        mounted: function () {
            var that = this;
            console.log(JSON.stringify(currentUser))
            if (currentUser.roleName == '区域经理' || currentUser.roleName == '大区经理' || currentUser.roleName == '销售管理' || currentUser.roleName == '总经理') {
                that.getTreeData();
            } else {
                that.getCompanyTree();
            }
        }
    });

</script>
</body>
</html>